﻿using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace movie.tool.library.hash
{
    public class SHA1Hash
    {
        public static string FileDigest(string filePath)
        {
            if (File.Exists(filePath))
            {
                try
                {
                    using (FileStream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read))
                    {
                        using (SHA1 sha1 = SHA1.Create())
                        {
                            byte[] bytes = sha1.ComputeHash(fileStream);
                            StringBuilder sb = new StringBuilder();
                            return string.Join(null, bytes.Select(item => string.Format("{0:x2}", item)));
                        }
                    }
                }
                catch (Exception e)
                {
                    return string.Empty;
                }
                
            }
            return string.Empty;
        }
    }
}
